package ModelLayer;
import java.util.HashMap;

/**
 * This class is a collection of all orders in the system.
 * 
 * @author Gruppe 4 
 * @version 5. juni 2012
 */
public class OrderCollection
{
    // Singleton
    private static OrderCollection instance;
    
    // instance variables
    private HashMap<Integer, Order> orders;
    
    /**
     * The constructor of the class initializes: orders.
     */
    private OrderCollection()
    {
        orders = new HashMap<Integer, Order>();
    }

    /**
     * Singleton controls that only one instance of this class is made!
     */
    public static OrderCollection getInstance()
    {
        if (instance == null)
        {
            instance = new OrderCollection();
        }
        return instance;
    }
    
    /**
     * This method adds an order to the HashMap.
     */
    public void addOrder(int orderNo, Order order)
    {
        Integer orderN = (Integer) orderNo;
        orders.put(orderN, order);
    }
    
    /**
     * This method uses the "get()" method on the HashMap, to find an order.
     */
    public Order findOrder(Integer orderNo)
    {        
        Order orderItem = orders.get(orderNo);
        return orderItem;
    }
    
    /**
     * This method returns the whole HashMap.
     */
    public HashMap<Integer, Order> ListAllOrders()
    {
        return orders;
    }
}
